<?php


namespace alipay;


class AppPay
{
    /**
     * 配置參數
     */
    public $config = array(
        'gatewayUrl' => "https://openapi.alipay.com/gateway.do",    /*支付宝网关*/
        'appId' => "2019050664390100",   /*微信申请成功之后邮件中的商户id*/
        'rsaPrivateKey' => "MIIEowIBAAKCAQEAo1DVNK01WQpv2Lj3ckL+QwSU2B1xivsqFOjUEEQb72KxJZzFCbPgXnmNj0BGQogD/r3nS9EvrJXWSp6RbnhrgXO1bFa57qEou/QMpX5PPvePl8qixzgduIBMu/v0rOSPuO7s1qlx8diuoZtm0dqKRjTS22CBKQN+3h2RWdJq96yy+QBfaQlYhs5w+cZSi4Rmb9RV7XYiFbMQXquegKmp375sRBVEr/TOpmd8NOrm2f7PlQSH35GS5TcJZcgL88NK1M/w6604f1qWIyCKu3kmFQPS4GzTaMZfpFVGHH9Wec1qo47ZXIhKMUvauuLcV5zM65g94JlstzOyciTiox7ZgQIDAQABAoIBAGMYayYZa2Np18/y/AJS8CEOKJqx0vF30WL6m6J7EVBB3CdsZoqqoJvyuZiQcZFxIqtx42S3u2vHR03jxW74lpLn+M+SGCPZmfPh88J/T+pvIKwEAp1LSY1oHCd8jExUK3kVUJQ4ILGUvvHEb7EqH/jVmJQQjI6sVlDENCwCZ3F8Wo4qWbmn4iV59DtxVR0RjBUph3Bd5F1+0IAeVH9z/YJofw/7unFdcsWfd1BrRbVflQMvsSRIoQ1/+5zkYbqqHX1yjPnQxOijLQBinozuKlMLzs1r4GIjUZ9aflGgJ9GA5uO4M0sp2AHSvRAXkGg9N3/9HsIllKjpRcBnz8LZDjkCgYEA1M0iwg4GxHHLq4awrgqS4BWCRSfqp86J/n8cMUWV2cQQ4jabVuhw4gQYVP/RbFR9QNZ0SSkkmPHTh6fWTU1xNei1TtS+dL5ssB4/QHIhu7URHjHV3ZBTbUReO4d5kxyRN7PDHXEF3Qg8U2rS+aWZP9y7zfvAtWpYCfuLhtadOgsCgYEAxHgHvlD4R4rbpSLpqCuqe/iCXq5PJu1VqDZfihX0Z2Cwh5257easn1Ld7zagvvMeRgUGipL7PXSIzKhnaIUackwDFNua1rJxqrfZdLn4XKEILsvnBTSmrm1ujVshy9nqRVGTrmer97AoFsbvlACvO3JOWmWY+l1WwTYzE3K7/iMCgYBM4v1e/fBmA/Ohut2VVI6y1jKmSADZtp9XS5flGY5GCzhKc452vS8kCnS8KV4CdRh4V8PWNz5Y4G8cQYEFlyiDYNw5alaSGcdtbtBNua8Egix4K2tpTV9HSH9/pLhBdf3mEVY7Cf4jWXlqbltiBfoz/83/Y6nCInVCzhcgleRi9wKBgCIDbcPDHNi174TNYIpe1OsVgOyHXOiuWg//KdcsKd3j3Wv9IH1RXD1RCV8qo/Wq/Wi94f4HqDthe3WDCjQMJyH2iuoHguz8g7U8kwckUx0mO9ZuMpayINE93M/YISe7mFVb5Cdjh2AgPTCETGHhJHU0OuBnim59zlEw4vLRAD7lAoGBAMAoBojfS1s0S+qriWZeRE/6UsFWrqAyJ9N7dcgHGF40h2sh1Fki1hqw+5dY0lToBj2zPSIE2d5NjsYrCcI0yl942x2CT7EpbzbHCMONMlbn1KcBfkOVK7fgt85b9J3IZK209ib9zb9tO9n1ziiT6/RYuU9hwm34HPkUBtsoVFb3",    /*开发者私钥*/
        'format'=>'JSON',
        'charset'=>'utf-8',
        'signType'=> 'RSA2',
        'alipayrsaPublicKey'=>'MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAm/j1QKrdEWyfAGyrmS6jBYDop1KfHltNum+v8yCGAYvGNeBd8iEg9WV5MG5X5Spxr3EZMFA5qF8hLCpOMfLYQWLhJOUvujMFuqyvT+ETSvR62/ZtoDlyqKpBO0+azp1ncUV5jXfd7WrPAM7nnuMEs3xvw6rshI+5e6OKjGTXUxbNmT3YGNe2zt7yG+8S7fDCqDky1ZvxWvQxzT2Z3ERovXE7IKw0HV/Jcl0q/GfTC1C2CDHQtosKNALzlehZcmtEISfGrmbq/V87+GxNU4hq7jGycgygadIEK7XWyoAlcu8BK9NoCl+kpcwcuKD/GuSDMEXmDPebNmEnHKFj5+4CEwIDAQAB' /*支付宝公钥*/
    );

    function app_pay($subject, $order_sn, $total_amount,$notify){
        require_once('aop/AopClient.php');
        require_once('aop/request/AlipayTradeAppPayRequest.php');
        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        $request = new \AlipayTradeAppPayRequest();
        $aop   =    new \AopClient();
        //SDK已经封装掉了公共参数，这里只需要传入业务参数
        $bizcontent    =    [
            'body'                =>    '明心堂',
            'subject'            =>    $subject,
            'out_trade_no'        =>    $order_sn,
            'timeout_express'    =>    '15m',//失效时间为 15分钟
            'total_amount'        =>    $total_amount,//价格
            'product_code'        =>    'QUICK_MSECURITY_PAY',
        ];
        //商户外网可以访问的异步地址 (异步回掉地址，根据自己需求写)
        $request->setNotifyUrl($notify);
        $request->setBizContent(json_encode($bizcontent));
        $aop->gatewayUrl=$this->config['gatewayUrl'];
        $aop->appId=$this->config['appId'];
        $aop->rsaPrivateKey=$this->config['rsaPrivateKey'];
        $aop->format=$this->config['format'];
        $aop->postCharset=$this->config['charset'];
        $aop->signType=$this->config['signType'];
        $aop->alipayrsaPublicKey=$this->config['alipayrsaPublicKey'];
        //这里和普通的接口调用不同，使用的是sdkExecute
        $response = $aop->sdkExecute($request);
        return $response;
        //htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义，实际打印到日志以及http传输不会有这个问题
    }
}